package zzz.Text.text8;

import java.util.ArrayList;
import java.util.Scanner;

public class Student {

    public static void Addlist(ArrayList<Student_page> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生id:");
        int stu_id = sc.nextInt();
        System.out.println("请输入学生名字:");
        String stu_name = sc.next();
        System.out.println("请输入学生年龄:");
        int stu_age = sc.nextInt();
        System.out.println("请输入学生地址:");
        String stu_address = sc.next();
        Student_page stu = new Student_page(stu_id, stu_name, stu_age, stu_address);
        list.add(stu);
    }

    public static void Search(ArrayList<Student_page> list) {
        for (int i = 0; i < list.size(); i++) {
            Student_page stu = list.get(i);
            System.out.println("ID:" + stu.getId() + "学生:" + stu.getName() + "年龄:" + stu.getAge() + "住址:" + stu.getAddress());
        }
    }

    public static void delete(ArrayList<Student_page> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除的ID");
        int did = sc.nextInt();
        for (int i = 0; i < list.size(); i++) {
            int sid = list.get(i).getId();
            if (sid == did) {
                list.remove(i);
                System.out.println("删除成功");
            } else {
                System.out.println("你输入的ID有误,删除失败");
            }
        }
    }
    public static void Replace(ArrayList<Student_page> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要修改的ID");
        int rid = sc.nextInt();
        for (int i = 0; i < list.size(); i++) {
             int sid = list.get(i).getId();
             Student_page stu = list.get(i);
             if(sid == rid){
                 System.out.println("请输入学生名字:");
                 String stu_name = sc.next();
                 stu.setName(stu_name);
                 System.out.println("请输入学生年龄:");
                 int stu_age = sc.nextInt();
                 stu.setAge(stu_age);
                 System.out.println("请输入学生地址:");
                 String stu_address = sc.next();
                 stu.setAddress(stu_address);
                 System.out.println("修改成功");
                 break;
             }else {
                 System.out.println("输入的ID有误,请重新输入");
             }
        }
    }
}